﻿using System.Collections.Specialized;
using System.Configuration;
using SpiderCore.Utility;

namespace SpiderCore.Ants
{
    /// <summary>
    /// 蚁后
    /// </summary>
    internal class AntQueen
    {
        private static AntQueen _antQueen;
        private static readonly  object _syncBoot=new object();
        private AntQueen()
        {
            
        }
        public static AntQueen GetInstance()
        {
            if (_antQueen == null)
            {
                lock (_syncBoot)
                {
                    if (_antQueen == null)
                    {
                        _antQueen = new AntQueen();
                    }
                }
            }
            return _antQueen;
        }
        /// <summary>
        /// 生产一个蚂蚁
        /// </summary>
        /// <returns></returns>
        public  Ant CreateAnt(string route )
        {
            NameValueCollection config = (NameValueCollection) ConfigurationManager.GetSection("SpiderRoute/Ant");
            string path = config[route];
            var ret=ReflectionHelper.CreateInstance<Ant>(path);
            return ret;
        }
    }
}
